#!/usr/bin/env python

import sys

from twisted.internet import gtk2reactor
gtk2reactor.install()

from twisted.internet import reactor
import jsonpickle

from comm.CommDispatcher import CommDispatcher
#import DeviceSystem
from MainController import MainController

from ui.gtk.mainwindow import MainWindow

def build_daemon():
    comm = CommDispatcher(osc_kwargs=dict(app_address='openlightingdesigner', root_address='daemon'))
    ds = DeviceSystem.DeviceSystem(comm=comm)

def on_window_destroyed(*args):
    reactor.stop()

if __name__ == '__main__':
    comm = CommDispatcher()
    #mclock = MasterClockGTK(fps=30)
    #ds = DeviceSystem.DeviceSystem(comm=comm)
    mc = MainController(comm=comm)
    
    w = MainWindow(DeviceSystem=mc.DeviceSystem, MainController=mc, comm=comm)
    w.window.connect('destroy', on_window_destroyed)
    #ds.from_json(filename='GlobalAttributes.json')
    #ds.from_json(filename='test.json')
    
    
    #print 'before:   ', ds.to_json(indent=None)
    
    
    
    #ds.from_json(string=s)
    
    
    
    #file = open('test.json', 'w')
    #file.write(ds.to_json(indent=None))
    #file.close()
    reactor.run()
